<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>DOM事件0级2级IE浏览器</title>
</head>
<body>
<button id="btn">按钮</button>
<script>
    var btn1=document.getElementById("btn");
    if (btn1.addEventListener){
        btn1.addEventListener("click",demo);//DOM2级事件
    }else if(btn1.attachEvment){
        btn1.attachEvment("click",demo);//IE浏览器事件处理
    }else{
        btn1.onclick=demo();//DOM0级事件
    }
    function demo() {
        alert("hello");
    }
</script>
</body>
</html>